home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE09 / CLINIC / LISTBOXU.PAS < prev    next >
Pascal/Delphi Source File  |  1996-02-18  |  2KB  |  68 lines

  1. unit Listboxu;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Slistbox;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     SListbox1: TSListbox;
  12.     SListbox2: TSListbox;
  13.     procedure ListboxScroll(Sender: TObject; ScrollCode, Pos: Word);
  14.     procedure ListboxSelChange(Sender: TObject);
  15.   private
  16.     { Private declarations }
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.DFM}
  27.  
  28. procedure TForm1.ListboxScroll(Sender: TObject; ScrollCode, Pos: Word);
  29. begin
  30.   if Sender = SListbox1 then
  31.     SListbox2.TopIndex := SListbox1.TopIndex
  32.   else
  33.     SListbox1.TopIndex := SListbox2.TopIndex;
  34. end;
  35.  
  36. {$ifdef SIMPLE}
  37. procedure TForm1.ListboxSelChange(Sender: TObject);
  38. begin
  39.   ListboxScroll(Sender, 0, 0);
  40. end;
  41. {$else}
  42. procedure TForm1.ListboxSelChange(Sender: TObject);
  43. var
  44.   Loop: Word;
  45.   Src, Dest: TListbox;
  46. begin
  47.   { Set up Src and Dest as original and mimic }
  48.   Src := Sender as TListbox;
  49.   Dest := SListbox1;
  50.   if Src = Dest then
  51.     Dest := SListbox2;
  52.   with Src do
  53.   begin
  54.     { Stop destination from flickering as we update it }
  55.     Dest.Items.BeginUpdate;
  56.     { Make multi-selections match in both listboxes }
  57.     if Dest.MultiSelect then
  58.       for Loop := 0 to Pred(Items.Count) do
  59.         Dest.Selected[Loop] := Selected[Loop]
  60.     else
  61.       Dest.ItemIndex := ItemIndex;
  62.     Dest.TopIndex := TopIndex;
  63.     Dest.Items.EndUpdate;
  64.   end;
  65. end;
  66. {$endif}
  67. end.
  68.